(* ===================================================================== *)
(** Outils pour maping scriptable des noms de variables pour affichage 
    @author Mathieu Barbin
    @date samedi 3 janvier 2009, 08:16:24 (UTC+0100) *)
(* ===================================================================== *)

(* Parsing : AST *)

type pattern = Specified of bool option array | Any 
type matching_item = int * (pattern * string * int list)

type anonyme_matching = matching_item list
and named_matching = string * anonyme_matching (* utile pour les definitions et les appels *) 
and option_matching = UseDefine of string | Anonymous of anonyme_matching 
and var_matching = string * option_matching
and bloc = string * (var_matching list) 

type bopmop_ast = 
    {
      includes : (int * string) list;
      defines : named_matching list;
      modules : bloc list
    }

let mop_line = ref 1
let mop_file = ref ""

(* Concatenation de plusieurs fichiers *)

let concat_ast un deux =
  {
    includes = [];
    defines = un.defines@deux.defines;
    modules = un.modules@deux.modules
  }

let ast_empty =
  {
    includes = [];
    defines = [];
    modules = []
  }

module Repr =
struct
  let pattern = function
    | Specified bo -> PartialBoolArray.to_string bo
    | Any -> "_"
	
  let elt = function
    | (pat, format, ind_list), arg -> 
	Printf.sprintf "%s -> %s %s [%d]" (pattern pat) format (Bplib.string_of_list string_of_int ", " "[" "]" ind_list) (Array.length arg)
end 
